package cn.edu.javaweb.superServlet;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.javaweb.utils.DBUtil;
@WebServlet("/AddNotice")
public class AddNotice extends HttpServlet {
	 DBUtil db; //声明对象 一定要赋值  否则空指针异常
	 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 this.doPost(request, response); 
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置Register.html里的编码
		request.setCharacterEncoding("utf-8");
		//获取用户输入的信息
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		String target = request.getParameter("target");
		String place = request.getParameter("place");
		String Stime = request.getParameter("Stime");
		String Etime = request.getParameter("Etime");
		System.out.println(title);
		System.out.println(content);
		System.out.println(target);
		System.out.println(place);
		System.out.println(Stime);
		System.out.println(Etime);
	
		db = new DBUtil(); //赋值 不会出现空指针异常
		db.init();  //初始化  加载驱动程序，得到连接对象  （搭桥）
		String SQL="insert into notice(title,content,target,place,Stime,Etime) values ('"+title+"','"+content+"','"+target+"','"+place+"','"+Stime+"','"+Etime+"')";
		int result = db.update(SQL); //对应的封装方法是update  调用并执行更新    excuteUpdate  返回值是int 
		System.out.println(SQL); 
		request.getRequestDispatcher("/SelectNotice").forward(request, response);
	}

}
